<template>
  <view class="record flexc">
    <view class="header">
      <u-tabs
        :current="tabCurrent"
        :scrollable="true"
        :list="tabList"
        keyName="title"
        lineColor="#CB0011"
        :lineWidth="28"
        :lineHeight="2"
        @click="tabClick"
        :itemStyle="{
          height: '88rpx',
          fontSize: '28rpx',
          color: '#9695A3',
        }"
        :activeStyle="{ fontWeight: 'bold', color: '#000000' }"
        :inactiveStyle="{}"></u-tabs>
    </view>
    <!-- 中间数据展示 发起提交-->
    <template v-if="tabCurrent == 0 || tabCurrent == 2">
      <!-- 二级tab -->
      <view class="nav flex-center">
        <view :class="navIndex == 1 ? 'nav-ac' : ''" @click="navBtn(1)">
          放苗服务记录表
        </view>
        <view :class="navIndex == 2 ? 'nav-ac' : ''" @click="navBtn(2)">
          养殖服务记录表
        </view>
      </view>
      <template v-if="tabCurrent == 0">
        <view class="flex1 over" style="padding-bottom: 50upx">
          <view class="wrap mb16">
            <template v-if="navIndex == 1">
              <view class="box flexc">
                <view class="">序号</view>
                <input
                  class="flex1"
                  type="text"
                  v-model="form1.seeding_no"
                  placeholder="请输入 不输入自动生成" />
              </view>
              <view class="box flexc" @click="showPopDate">
                <view class="">
                  <text class="sc">*</text>
                  放苗日期
                </view>
                <view class="box-b flex">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.seeding_date"
                    placeholder="默认选择当天" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc">
                <view class="">
                  <text class="sc">*</text>
                  批次
                </view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form1.batch"
                  placeholder="请输入" />
              </view>
              <view class="box flexc" @click="goyzh">
                <view class="">
                  <text class="sc">*</text>
                  养殖户
                </view>
                <view class="flex box-b">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form1.farmer_title"
                    placeholder="请选择" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc">
                <view class="">地址</view>
                <input
                  class="flex1"
                  type="text"
                  disabled
                  v-model="form1.address"
                  placeholder="请选择" />
              </view>
              <view class="box flexc">
                <view class="">中间商</view>
                <input
                  class="flex1"
                  type="text"
                  disabled
                  v-model="form1.broker_title"
                  placeholder="请选择" />
              </view>

              <view class="box flexc">
                <view class="">
                  <text class="sc">*</text>
                  放苗量
                </view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form1.seeding_number"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">苗源</view>
                <input
                  class="flex1"
                  type="text"
                  v-model="form1.seeding_source"
                  placeholder="请输入" />
              </view>
            </template>
            <template v-else>
              <view class="box flexc">
                <view class="">序号</view>
                <input
                  class="flex1"
                  type="text"
                  v-model="form.breed_no"
                  placeholder="请输入 不输入自动生成" />
              </view>
              <view class="box flexc" @click="showPopDate">
                <view class="">
                  <text class="sc">*</text>
                  服务日期
                </view>
                <view class="box-b flex">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form.service_date"
                    placeholder="默认选择当天" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>

              <view class="box flexc" @click="goyzh">
                <view class="">
                  <text class="sc">*</text>
                  养殖户
                </view>
                <view class="flex box-b">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form.farmer_title"
                    placeholder="请选择" />
                  <image
                    src="/static/login/pop-arrow.png"
                    mode="aspectFit"></image>
                </view>
              </view>
              <view class="box flexc">
                <view class="">地址</view>
                <input
                  class="flex1"
                  type="text"
                  disabled
                  v-model="form.address"
                  placeholder="请选择" />
              </view>
              <view class="box flexc">
                <view class="">中间商</view>
                <input
                  class="flex1"
                  type="text"
                  disabled
                  v-model="form.broker_title"
                  placeholder="请选择" />
              </view>
              <!-- @click="showPop(1)" -->
              <view class="box flexc">
                <view class="">批次</view>
                <view class="box-b flex">
                  <input
                    class="flex1"
                    type="text"
                    disabled
                    v-model="form.batch"
                    placeholder="请选择" />
                </view>
              </view>
              <view class="box flexc">
                <view class="">
                  <text class="sc">*</text>
                  养殖量
                </view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form.breed_num"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">日龄</view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form.day_age"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">死淘数</view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form.dead_num"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">余料</view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form.surplus_material"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">费用</view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form.cost"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">抽样只数</view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form.sampling_number"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">重量(kg)</view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form.weight"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">均量(kg)</view>
                <input
                  class="flex1"
                  type="number"
                  v-model="form.avg_weight"
                  placeholder="请输入" />
              </view>
              <view class="box flexc">
                <view class="">健康状况</view>
                <input
                  class="flex1"
                  type="text"
                  v-model="form.health_status"
                  placeholder="请输入" />
              </view>
            </template>
          </view>
          <view class="wrap mb16">
            <view class="box flexc">
              <view class="">备注</view>
              <u--textarea
                v-model="info"
                height="200"
                border="none"
                maxlength="200"
                placeholder="请输入"
                count></u--textarea>
            </view>
          </view>
          <record_status_userVue :formType="navIndex" />
        </view>
        <view class="footer flex-between">
          <view class="box-icon column-flex-center" @click="submitForm(0)">
            <image src="/static/order/5.png" mode="aspectFit"></image>
            <view class="">存草稿</view>
          </view>
          <view class="btn" @click="submitForm(1)">提交</view>
        </view>
      </template>
      <!-- 养殖记录 -->
      <template v-if="tabCurrent == 2">
        <view class="search flex">
          <image src="/static/order/search.png" mode="aspectFit"></image>
          <input
            type="text"
            v-model="keyword"
            @confirm="searchBtn"
            class="flex1"
            placeholder="搜索" />
        </view>
        <view class="flex1 over" style="padding-bottom: 50upx">
          <scroll-view
            scroll-y="true"
            style="height: 100%"
            @scrolltolower="loadingMore">
            <view class="content-wrap">
              <view
                class="content-box"
                v-for="(item, index) in scrollList"
                :key="index"
                @click="goDetail(item)">
                <view class="flex-between">
                  <view class="flex">
                    <view :class="['t', item.status == 9 ? 'ac4' : '']">
                      {{ item.title }}
                    </view>
                    <view class="edit-text" v-if="item.pid > 0">修改</view>
                  </view>
                  <view class="t1">
                    {{ item.created_at }}
                  </view>
                </view>
                <view class="no flex-between">
                  <view class="">
                    序号：{{ item.seeding_no || item.breed_no || "" }}
                  </view>
                  <view
                    class="cred"
                    v-if="item.pid > 0"
                    @click.stop="historyBtn(item)">
                    历史数据
                  </view>
                </view>
                <view class="t2 mb12">
                  服务日期：{{ item.seeding_date || item.service_date }}
                </view>
                <view class="t2">养殖户：{{ item.farmer_title }}</view>
                <view class="flex-between mt34">
                  <view class="flex">
                    <image
                      class="img"
                      v-if="item.status != 9"
                      src="/static/order/3.png"
                      mode="aspectFit"></image>
                    <image
                      class="img"
                      v-if="item.status == 9"
                      src="/static/order/4.png"
                      mode="aspectFit"></image>
                    <!-- :class="item.status == 3 ? 'ac1' : 'ac'" -->
                    <text :class="['ac', item.status == 9 ? 'ac4' : '']">
                      {{ item.user_name }}
                    </text>
                  </view>
                  <!-- status 1通过 2拒绝 -->
                  <view
                    :class="
                      item.status == 1 ||
                      item.status == 2 ||
                      item.status == 4 ||
                      item.status == 6
                        ? 'ac2'
                        : item.status == 8
                        ? 'ac3'
                        : 'ac4'
                    ">
                    {{ item.status_name }}
                  </view>
                </view>
              </view>
            </view>
            <w_loadmore :status="loadStatus"></w_loadmore>
          </scroll-view>
        </view>
      </template>
    </template>
    <!-- 查看报表 -->
    <template v-if="tabCurrent == 1">
      <view class="nav1 flex-between">
        <view class="flex" @click="() => (btShow = true)">
          <view class="">{{ btTitle }}</view>
          <image
            src="/static/order/d.png"
            class="d-icon"
            mode="aspectFit"></image>
        </view>
        <view class="flex" @click="exportInfo">
          <image
            src="/static/order/e.png"
            mode="aspectFit"
            class="e-icon"></image>
          <view class="nav1-text">导出</view>
        </view>
      </view>
      <view class="time-box">
        <view class="flex" @click="() => (showTime = true)">
          <view class="">选择时间</view>
          <image
            src="/static/order/d.png"
            mode="aspectFit"
            class="d1-icon"></image>
        </view>
        <view class="time-box-text">{{ showDateTitle }}</view>
      </view>
      <view class="flex1 over wrap1" style="padding-bottom: 50upx">
        <view class="">表单提交次数</view>
        <view class="wrap1-num">{{ total }}</view>
        <view class="wrap1-des">{{ btTitle }}</view>
        <view class="">
          <zb-table
            :show-header="true"
            :columns="column"
            :border="true"
            :flt="true"
            :cell-style="cellStyle"
            :cell-header-style="cellHeaderStyle"
            :data="tableData"></zb-table>
        </view>
        <view class="page-set">
          <uni-pagination
            title="标题文字"
            :current="page"
            @change="pageBtn"
            :total="total"></uni-pagination>
        </view>
      </view>
    </template>
    <!-- 选择时间的弹框 -->
    <pop_timeVue
      :showTime="showTime"
      :mode="mode"
      @tiemCheck="tiemCheck"
      @confirmDate="confirmDate"
      @closeTime="() => (showTime = false)" />
    <u-calendar
      color="#DA4334"
      @confirm="confirmDate1"
      @close="showDate = false"
      :show="showDate"
      :maxDate="maxDate"
      :minDate="minDate"
      :default-date="defaultDate"
      :month-num="12"
      mode="single"></u-calendar>

    <!-- 中间商、养殖户 -->
    <u-picker
      @cancel="() => (show = false)"
      @confirm="confirmPicker"
      :show="show"
      confirmColor="#DA4334"
      :columns="farmerList"
      keyName="title"></u-picker>

    <!-- 第一个点击弹框 -->
    <pop_navVue
      :show="btShow"
      :btList="btList"
      @popShowBtn="popShowBtn"
      @closeBtn="() => (btShow = false)" />
  </view>
</template>

<script>
const d = new Date();
const year = d.getFullYear();
let month = d.getMonth() + 1;
month = month < 10 ? `0${month}` : month;
const date = d.getDate() < 10 ? `0${d.getDate()}` : d.getDate();
const maxDate = new Date(year + 1, 0, 0).getTime();
const minDate = new Date(year, 0, 1).getTime();
const defaultDate = [`${year}-${month}-${date}`];
const monthNum = 12;
import w_loadmoreVue from "../../../components/w_loadmore/w_loadmore.vue";
import utils from "../../../plugin/util.js";
import pop_timeVue from "../../../components/order/pop_time.vue";
import pop_navVue from "../../../components/order/pop_nav.vue";
import record_status_userVue from "../../../components/order/record_status_user.vue";
export default {
  components: {
    record_status_userVue,
    pop_navVue,
    pop_timeVue,
    w_loadmoreVue,
  },
  data() {
    return {
      monthNum,
      maxDate,
      minDate,
      defaultDate,
      loadStatus: "loadmore",
      show: false,
      info: "",
      tabCurrent: 0,
      tabList: [
        { title: "发起提交", value: 0 },
        { title: "查看报表", value: 1 },
        { title: "查看数据", value: 2 },
      ],
      navIndex: 1,
      column: [],
      tableData: [],
      showTime: false, //时间弹框/
      timeIndex: null,
      showTimeList: [
        "昨天",
        "本周",
        "本月",
        "近7天",
        "近30天",
        "近90天",
        "近180天",
        "选择时间段",
      ],
      showDate: false, //日历弹框
      mode: "range", //single单个---range范围
      orders: [],
      farmerList: [],
      farmerList0: [],
      farmerList1: [],
      farmerList2: [],
      popIndex: null,
      form: {
        service_date: "",
        farmer_id: "",
        broker_id: "",
        address: "",
        breed_num: "",
        day_age: "",
        dead_num: "",
        surplus_material: "",
        cost: "",
        sampling_number: "",
        weight: "",
        avg_weight: "",
        health_status: "",
        info: "",
        is_draft: "0", //是草稿1--0不是
        farmer_title: "",
        broker_title: "",
        breed_no: "",
        batch_title: "",
        batch: "",
      },
      form1: {
        seeding_no: "",
        seeding_date: "",
        farmer_id: "",
        broker_id: "",
        batch: "",
        farmer_title: "",
        broker_title: "",
        address: "",
        info: "",
        seeding_number: "",
        info: "",
        is_draft: "0",
        seeding_source: "",
      },
      userList: [],
      action: {
        1: "主管",
        2: "经理",
        3: "财务",
      },
      page: "1",
      limit: "10",
      total: 0,
      nomore: false,
      scrollList: [],
      btShow: false,
      btList: {
        1: "放苗服务记录",
        2: "养殖服务记录",
      },
      btTitle: "放苗服务记录",
      start_time: "",
      end_time: "",
      keyword: "",
      showDateTitle:
        utils.timeFormat(
          new Date(`${new Date().getFullYear()}` + "-" + "01-01")
        ) +
        "-" +
        utils.timeFormat(
          new Date(`${new Date().getFullYear()}` + "-" + "12-31")
        ),
      isDetail: false,
      info1: "",
      info2: "",
      isyzh: false, ///养殖户是否点击了
    };
  },
  created() {
    //this.getFarmer();
    // this.getBroker();

    this.getDetail();
    this.getDetail1();
  },
  onShow() {
    //   if (uni.getStorageSync("checkAddress")) {
    //     const info = JSON.parse(uni.getStorageSync("checkAddress"));
    //     if (this.navIndex == 2) {
    //       this.form.address = info.address;
    //     } else {
    //       this.form1.address = info.address;
    //     }
    //     console.log("地址---", this.form1.address);
    //     uni.removeStorageSync("checkAddress");
    //   }
    //详情页面返回，刷新数据
    if (this.isDetail) {
      this.page = 1;
      this.nomore = false;
      if (this.navIndex == 1) {
        this.getSeeding();
      } else {
        this.getBreed();
      }

      this.isDetail = false;
    }
    //养殖户返回，赋值
    if (uni.getStorageSync("checkAddress")) {
      const obj = JSON.parse(uni.getStorageSync("checkAddress"));
      if (this.navIndex == 1) {
        this.form1.farmer_id = obj.farmer_id;
        this.form1.farmer_title = obj.title;
        this.form1.broker_id = obj.broker_id;
        this.form1.address = obj.address;
        this.form1.broker_title = obj.broker_name;
      } else {
        this.form.farmer_id = obj.farmer_id;
        this.form.farmer_title = obj.title;
        this.form.broker_id = obj.broker_id;
        this.form.broker_title = obj.broker_name;
        this.form.address = obj.address;
        this.getBatch(obj.farmer_id);
      }

      //this.isyzh = false
      uni.removeStorageSync("checkAddress");
    }
  },
  methods: {
    goyzh() {
      //this.isyzh = true
      this.toRoute("/select-address?isyzh=1");
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 0) {
        return {
          color: "#DA4334",
          fontSize: "24rpx",
        };
      }
      if (
        (Object.keys(row)[8] == "status_text" && columnIndex === 8) ||
        (Object.keys(row)[16] == "status_text" && columnIndex === 16)
      ) {
        if (row.status_text.indexOf("失败") > -1) {
          return {
            color: "#DA4334",
            fontSize: "24rpx",
          };
        }
        if (row.status_text === "已撤销") {
          return {
            color: "#8d8d8d",
            fontSize: "24rpx",
          };
        }
      }
      return {
        color: "#171717",
        fontSize: "24rpx",
      };
    },
    cellHeaderStyle() {
      return {
        backgroundColor: "#F6F1F1",
        color: "#707072",
        fontSize: "24rpx",
      };
    },
    exportInfo() {
      let obj = {
        type: this.timeIndex == null ? "" : this.timeIndex + 1,
        start_time: this.start_time,
        end_time: this.end_time,
        form_type: this.navIndex,
      };
      this.$store.dispatch("exportInfo", obj);
    },
    //点击历史数据
    historyBtn(item) {
      this.toRoute({
        path: "section-detail",
        query: {
          id: item.pid,
          type: item.type, //1--放苗 2--养殖
        },
      });
    },
    //放苗
    getDetail() {
      this.$api({
        url: "/get_seeding_service_log_detail",
        method: "get",
        data: {
          type: "1",
        },
      }).then((res) => {
        if (res.code === 200 && Object.keys(res.data).length > 0) {
          this.form1 = res.data;
          this.info1 = res.data.info;
          this.info = this.info1;
        }
      });
    },
    //养殖
    getDetail1() {
      this.$api({
        url: "/get_breed_service_log_detail",
        method: "get",
        data: {
          type: "1",
        },
      }).then((res) => {
        if (res.code === 200 && Object.keys(res.data).length > 0) {
          this.form = res.data;
          this.info2 = res.data.info;
        }
      });
    },
    //点击数据跳转到详情页面
    goDetail(item) {
      if (item.pid > 0) {
        this.toRoute({
          path: "edit-record",
          query: {
            id: item.id,
            type: this.navIndex, //1--放苗 2--养殖
            pid: true,
          },
        });
      } else {
        this.toRoute({
          path: "section-detail",
          query: {
            id: item.id,
            type: this.navIndex, //1--放苗 2--养殖
          },
        });
      }
      this.isDetail = true;
    },
    //获取批次
    getBatch(farmer_id) {
      // this.farmerList1 = [];
      this.$api({
        url: "/batch_list",
        method: "get",
        data: { farmer_id },
      }).then((res) => {
        if (res.code === 200) {
          if (this.navIndex != 1) {
            this.form.batch = res.data.length > 0 ? res.data[0].batch : "";
          }
        }
      });
    },
    searchBtn() {
      console.log("11111111");
      this.page = 1;
      this.nomore = false;
      if (this.navIndex == 1) {
        this.getSeeding();
      } else {
        this.getBreed();
      }
    },
    loadingMore() {
      if (this.nomore) return;
      this.page++;
      if (this.navIndex == 1) {
        this.getSeeding(true);
      } else {
        this.getBreed(true);
      }
    },
    popShowBtn(k) {
      this.btShow = false;
      this.page = 1;
      this.bIndex = k;
      this.btTitle = this.btList[k];
      if (k == 1) {
        this.getSeeding();
      } else {
        this.getBreed();
      }
    },
    //加载更多
    loadingMore() {
      if (this.nomore) return;
      this.page++;
      if (this.navIndex == 1) {
        this.getSeeding(true);
      } else {
        this.getBreed(true);
      }
    },
    //放苗的查看数据
    getSeeding(flg = false) {
      const page = flg ? this.page : (this.page = 1);
      const type = this.timeIndex == null ? "" : this.timeIndex + 1;
      this.$api({
        url: "/get_seeding_service_log_list",
        method: "get",
        data: {
          page: this.page,
          limit: this.limit,
          type,
          start_time: this.start_time,
          end_time: this.end_time,
          option_type: this.tabCurrent == 2 ? "" : "1",
          keyword: this.keyword,
        },
      }).then((res) => {
        if (res.code === 200) {
          this.total = res.data.total;
          if (this.tabCurrent == 1) {
            this.tableData = res.data.list;
            this.showTime = false;
            this.showDate = false;
            this.column = [
              {
                name: "seeding_no",
                label: "序号",
                fixed: true,
                width: 100,
                align: "center",
                emptyString: "--",
              },
              {
                name: "seeding_date",
                label: "放苗日期",
                sorter: false,
                align: "center",
              },
              {
                name: "batch",
                label: "批次",
                sorter: false,
                align: "center",
              },
              {
                name: "farmer_title",
                label: "养殖户",
                align: "center",
              },
              { name: "address", label: "地址", align: "center" },
              {
                name: "broker_title",
                label: "中间商",
                align: "center",
              },
              {
                name: "seeding_number",
                label: "放苗量",
                align: "center",
              },
              { name: "info", label: "备注", align: "center" },
              {
                name: "status_text",
                label: "审核状态",
                align: "center",
              },
            ];
          } else {
            if (flg) {
              this.scrollList = this.scrollList.concat(res.data.list);
            } else {
              this.scrollList = res.data.list;
            }
            this.nomore =
              res.data.total / this.limit > this.page ? false : true;
            this.loadStatus = this.nomore ? "nomore" : "loading";
          }
        }
      });
    },
    confirmDate1(e) {
      if (this.navIndex == 1) {
        this.form1.seeding_date = e[0];
      } else {
        this.form.service_date = e[0];
        if (this.form.batch) {
          const date =
            new Date(this.form.service_date) - new Date(this.form.batch_title);
          this.form.day_age = date / (1000 * 60 * 60 * 24);
        }
      }
      this.showDate = false;
    },
    //选择时间段事件
    confirmDate({ e, data, index }) {
      console.log("当前时间段---", e);
      this.start_time = e[0];
      this.end_time = e[e.length - 1];
      this.timeIndex = index;
      this.showDateTitle = data;
      if (this.navIndex == 1) {
        this.getSeeding();
      } else {
        this.getBreed();
      }
    },
    //点击分页事件
    pageBtn(e) {
      console.log("分页----", e);
      this.page = e.current;
      if (this.bIndex == 1) {
        this.getSeeding(true);
      } else {
        this.getBreed(true);
      }
    },
    //养殖服务列表
    getBreed(flg = false) {
      const page = flg ? this.page : (this.page = 1);
      const type = this.timeIndex == null ? "" : this.timeIndex + 1;
      this.$api({
        url: "/get_breed_service_log_List",
        method: "get",
        data: {
          page,
          limit: this.limit,
          type,
          keyword: this.keyword,
          start_time: this.start_time,
          end_time: this.end_time,
          option_type: this.tabCurrent == 2 ? "" : "1",
        },
      }).then((res) => {
        if (res.code === 200) {
          this.total = res.data.total;
          if (this.tabCurrent == 1) {
            this.tableData = res.data.list;

            this.showTime = false;
            this.showDate = false;
            this.column = [
              {
                name: "breed_no",
                label: "序号",
                fixed: true,
                width: 100,
                align: "center",
                emptyString: "--",
              },
              {
                name: "service_date",
                label: "服务日期",
                sorter: false,
                align: "center",
              },
              {
                name: "farmer_title",
                label: "养殖户",

                align: "center",
              },
              { name: "address", label: "地址", align: "center" },
              {
                name: "broker_title",
                label: "中间商",
                align: "center",
              },
              { name: "batch", label: "批次", align: "center" },
              {
                name: "breed_num",
                label: "养殖量",
                align: "center",
              },
              { name: "day_age", label: "日龄", align: "center" },
              {
                name: "dead_num",
                label: "死淘数",
                align: "center",
              },
              {
                name: "surplus_material",
                label: "余料",
                align: "center",
              },
              { name: "cost", label: "费用", align: "center" },
              {
                name: "sampling_number",
                label: "抽样只数",
                align: "center",
              },
              { name: "weight", label: "重量", align: "center" },
              {
                name: "avg_weight",
                label: "均量",
                align: "center",
              },
              {
                name: "health_status",
                label: "健康状况",
                align: "center",
              },
              { name: "info", label: "备注", align: "center" },
              {
                name: "status_text",
                label: "审核状态",
                align: "center",
              },
            ];
          } else {
            if (flg) {
              this.scrollList = this.scrollList.concat(res.data.list);
            } else {
              this.scrollList = res.data.list;
            }
            this.nomore =
              res.data.total / this.limit > this.page ? false : true;
            this.loadStatus = this.nomore ? "nomore" : "loading";
          }
        }
      });
    },
    //跳转到地址页面
    goAddress() {
      this.toRoute("/select-address");
    },
    checkObj(obj, k) {
      // 遍历对象中的每个字段
      for (let key in obj) {
        // 跳过production_section_four_product_no字段
        // console.log(k, "k--------", key);
        if (k.includes(key) && !obj[key]) {
          return false;
        }
      }
      return true;
    },
    //存草稿，提交
    submitForm(k) {
      if (this.navIndex == 1) {
        //放苗
        this.form1.is_draft = k == 0 ? "1" : "0";

        if (!this.form1.seeding_date) {
          this.form1.seeding_date = new Date()
            .toLocaleDateString()
            .replace(/\//g, "-");
        }
        // this.form1.farmer_id = this.form.farmer_id;
        // this.form1.farmer_title = this.form.farmer_title;
        // this.form1.broker_id = this.form.broker_id;
        // this.form1.broker_title = this.form.broker_title;
        // this.form1.info = this.form.info;
        const arr = ["seeding_date", "batch", "farmer_title", "seeding_number"];
        const s = this.checkObj(this.form1, arr);
        if (!s && k != 0) {
          uni.showToast({
            title: "请填写完整",
            icon: "none",
          });
          return;
        }
        this.$api({
          url: "/save_seeding_service_log",
          method: "post",
          data: {
            ...this.form1,
            info: this.info,
          },
        }).then((res) => {
          uni.showToast({
            title: res.msg,
            icon: "none",
          });
          if (res.code === 200 && k != 0) {
            Object.keys(this.form1).forEach((key) => (this.form1[key] = ""));
          }
        });
      } else {
        this.form.is_draft = k == 0 ? "1" : "0";
        if (!this.form.service_date) {
          this.form.service_date = new Date()
            .toLocaleDateString()
            .replace(/\//g, "-");
        }
        const arr = ["service_date", "farmer_title", "breed_num"];
        const s = this.checkObj(this.form, arr);
        if (!s && k != 0) {
          uni.showToast({
            title: "请填写完整",
            icon: "none",
          });
          return;
        }
        this.$api({
          url: "/save_breed_service_log",
          method: "post",
          data: {
            ...this.form,
            info: this.info,
          },
        }).then((res) => {
          uni.showToast({
            title: res.msg,
            icon: "none",
          });
          if (res.code === 200 && k != 0) {
            Object.keys(this.form).forEach((key) => (this.form[key] = ""));
          }
        });
      }
    },
    //服务日期
    showPopDate() {
      this.mode = "single";
      this.showDate = true;
    },
    //显示中间商，养殖户
    showPop(k) {
      this.show = true;
      this.popIndex = k;
      this.farmerList = this["farmerList" + k];
    },
    confirmPicker(e) {
      console.log(e, "养殖户。中阿金是");
      if (this.navIndex == 1) {
        this.form1.farmer_id = e.value[0].farmer_id;
        this.form1.farmer_title = e.value[0].title;
        this.form1.broker_id = e.value[0].broker_id;
        this.form1.address = e.value[0].address;
        this.form1.broker_title = e.value[0].broker_name;
      } else {
        if (this.popIndex == 0) {
          this.form.farmer_id = e.value[0].farmer_id;
          this.form.farmer_title = e.value[0].title;
          this.form.broker_id = e.value[0].broker_id;
          this.form.broker_title = e.value[0].broker_name;
          this.form.address = e.value[0].address;
        } else {
          this.form.batch_title = e.value[0].seeding_date;
          this.form.batch = e.value[0].batch;
          if (this.form.service_date) {
            const date =
              new Date(this.form.service_date) -
              new Date(e.value[0].seeding_date);
            this.form.day_age = date / (1000 * 60 * 60 * 24);
          }
        }
      }

      this.show = false;
    },
    //中间商
    getBroker() {
      this.farmerList1 = [];
      this.$api({
        url: "/broker_list",
        method: "get",
        data: {},
      }).then((res) => {
        if (res.code == 200) {
          this.farmerList1.push(res.data);
        }
      });
    },
    //获取养殖户列表
    getFarmer() {
      this.farmerList0 = [];
      this.$api({
        url: "/farmer_list",
        method: "get",
      }).then((res) => {
        if (res.code == 200) {
          this.farmerList0.push(res.data);
        }
      });
    },
    tabClick(e) {
      console.log("点击tab", e);
      this.tabCurrent = e.value;
      this.timeIndex = null;
      this.navIndex = 1;
      if (this.tabCurrent == 1 || this.tabCurrent == 2) {
        this.page = 1;
        this.nomore = false;
        this.loadStatus = "loadmore";
        this.getSeeding();
      }
    },
    //导航一
    navBtn(k) {
      this.navIndex = k;
      if (k == 1) {
        this.info = this.info1;
      } else {
        this.info = this.info2;
      }
      if (this.tabCurrent == 2) {
        this.page = 1;
        this.nomore = false;
        this.loadStatus = "loadmore";
        if (k == 1) {
          this.getSeeding();
        } else {
          this.getBreed();
        }
      }
    },
    //查看列表的时间弹框选择
    tiemCheck({ k, data }) {
      this.timeIndex = k;
      // if (k == this.showTimeList.length - 1) {
      //   this.showDate = true;
      // } else {
      this.showDateTitle = data;
      if (this.navIndex == 1) {
        this.getSeeding();
      } else {
        this.getBreed();
      }
      // }/
    },
    //日历弹框
    confirm(e) {
      console.log(e);
      if (this.mode == "single") {
        if (this.navIndex == 1) {
          this.form1.seeding_date = e[0];
        } else {
          this.form.service_date = e[0];
        }
      }
      this.showDate = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.record {
  width: 100%;
  height: 100%;
  background: #f5f7f9;

  ::v-deep .u-tabs__wrapper__nav__item {
    flex: 1;
  }
  ::v-deep .u-popup {
    flex: 0 !important;
  }
  .header {
    height: 88upx;
    width: 100%;
    background: #fff;
  }
  .nav {
    padding: 20upx 0;
    & > view {
      width: 192rpx;
      height: 52rpx;
      text-align: center;
      line-height: 52upx;
      background: #ffffff;
      border-radius: 8rpx 8rpx 8rpx 8rpx;
      font-size: 24rpx;
      color: #9695a3;
      margin-right: 52upx;
    }
    .nav-ac {
      background: #da4334;
      color: #ffffff;
    }
  }
  .wrap {
    background: #fff;
    padding: 0 32upx;
    .box {
      padding: 28upx 0;
      font-size: 32rpx;
      border-bottom: 1rpx solid #e4e4e4;
      & > view {
        font-size: 32rpx;
        color: #161616;
      }
      & > input {
        font-size: 32rpx;
        height: 28upx;
        margin-top: 28upx;
      }

      .box-b {
        margin-top: 28upx;
        & > input {
          height: 28upx;
          font-size: 32rpx;
        }
        & > image {
          width: 12upx;
          height: 21upx;
        }
      }
      ::-webkit-input-placeholder {
        color: #a0a0a0;
      }
    }
  }
  .footer {
    background: #fff;
    padding: 8upx 32upx;

    padding-bottom: env(safe-area-inset-bottom);
    .box-icon {
      font-size: 24rpx;
      color: #000000;
      & > image {
        width: 39upx;
        height: 38upx;
        margin-bottom: 10upx;
      }
    }
    .btn {
      width: 580rpx;
      height: 80rpx;
      background: #da4334;
      border-radius: 422rpx 422rpx 422rpx 422rpx;
      border: 1rpx solid #dafbff;
      font-weight: 500;
      font-size: 28rpx;
      color: #ffffff;
      text-align: center;
      line-height: 80upx;
    }
  }
  .nav1 {
    height: 88rpx;
    background: #ffffff;
    font-size: 32rpx;
    color: #161616;
    box-sizing: border-box;
    padding: 0 32upx;
    .d-icon {
      width: 20rpx;
      height: 13rpx;
      margin-left: 18upx;
    }
    &-text {
      font-size: 28rpx;
      color: #da4334;
      margin-left: 6upx;
    }
    .e-icon {
      width: 28rpx;
      height: 28rpx;
    }
  }
  .time-box {
    padding: 30upx 32upx 16upx;
    font-size: 28rpx;
    color: #1c2127;
    .d1-icon {
      width: 12upx;
      height: 12upx;
      margin-left: 4upx;
    }
    &-text {
      font-size: 24rpx;
      color: #6f6e74;
      margin-top: 48upx;
    }
  }
  .wrap1 {
    background: #fff;
    padding: 28upx 32upx;
    font-size: 28rpx;
    color: #171717;
    &-num {
      font-size: 48rpx;
      padding: 48upx 0;
      border-bottom: 1rpx solid #e4e4e4;
    }
    &-des {
      font-size: 28rpx;
      color: #161616;
      margin: 28upx 0 24upx;
    }
  }

  .search {
    width: 702rpx;
    height: 68rpx;
    background: #ffffff;
    border-radius: 12rpx 12rpx 12rpx 12rpx;
    border: 2rpx solid rgba(0, 0, 0, 0.06);
    margin: 0 auto 20upx;
    box-sizing: border-box;
    padding: 0 20upx;
    font-size: 28rpx;
    & > image {
      width: 32upx;
      height: 32upx;
      margin-right: 16upx;
    }
  }
  .content-wrap {
    padding: 0 24upx;
    .content-box {
      padding: 32upx 32upx 28upx;
      background: #fff;
      margin-bottom: 20upx;
      font-size: 24rpx;
      color: #8d8d8d;
      .t {
        font-size: 32rpx;
        color: #171717;
      }
      .t1 {
        color: #afafaf;
      }
      .edit-text {
        width: 78rpx;
        height: 36rpx;
        background: #f17303;
        font-size: 24rpx;
        color: #ffffff;
        border-radius: 14upx 0 14upx 0;
        margin-left: 16upx;
        text-align: center;
        line-height: 36upx;
      }
      .no {
        margin-top: 30upx;
        margin-bottom: 12upx;
        color: #8d8d8d;
      }
      .cred {
        font-size: 24rpx;
        color: #da4334;
      }
      .t2 {
        color: #8d8d8d;
      }
      .mb12 {
        margin-bottom: 12upx;
      }
      .ac {
        font-size: 26rpx;
        color: #8d8d8d;
      }
      .ac1 {
        font-size: 26rpx;
        color: #171717;
      }
      .img {
        width: 40upx;
        height: 40upx;
        margin-right: 8upx;
      }
      .ac2 {
        font-size: 26rpx;
        color: #f17303;
      }
      .ac3 {
        font-size: 26rpx;
        color: #0cb18e;
      }
      .ac4 {
        font-size: 26rpx;
        color: #8d8d8d;
      }
      .mt34 {
        margin-top: 34upx;
      }
    }
  }
  .page-set {
    margin: 20upx 0;
  }
  .sc {
    color: #da4334;
  }
}
</style>
